home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1994 December / PSL Monthly Shareware CD-ROM (Public Software Library)(December 1994).bin / prgmming / win / pascal / filecopy.pas < prev    next >
Pascal/Delphi Source File  |  1991-08-23  |  9KB  |  301 lines

  1. Program FileCopy;
  2. {$D FileCopy}
  3. {$I-}
  4. uses WObjects, WinTypes, WinProcs;
  5.  
  6. Const
  7.   AppName:PChar = 'FileCopy';
  8.   rgb_Yellow = $0000FFFF;
  9.   rgb_Blue   = $00FF0000;
  10.   rgb_Red    = $000000FF;
  11.  
  12. Var
  13.   SourceNumA : Integer;
  14.   SourceNumB : Integer;
  15.   SourceNumC : Integer;
  16.   SourceNumD : Integer;
  17.   TargetNumA : Integer;
  18.   TargetNumB : Integer;
  19.   TargetNumC : Integer;
  20.   TargetNumD : Integer;
  21.   Source     : Char;
  22.   Target     : Char;
  23.   SourceFile : String[30];
  24.   TargetFile : String[30];
  25.   Answer     : Boolean;
  26.   NumColors  : Integer;
  27.  
  28. const
  29.   id_Push1  = 101;
  30.   id_Rad1   = 102;
  31.   id_Rad2   = 103;
  32.   id_Rad3   = 104;
  33.   id_Rad4   = 105;
  34.   id_Rad5   = 106;
  35.   id_Rad6   = 107;
  36.   id_Rad7   = 108;
  37.   id_Rad8   = 109;
  38.   id_Check1 = 110;
  39.   id_SourceGroup = 111;
  40.   id_TargetGroup = 112;
  41.   id_Entry1 = 113;
  42.   id_Entry2 = 114;
  43.   Text1 = 115;
  44.   Text2 = 116;
  45.  
  46. type
  47.   CopyFile = object(TApplication)
  48.     procedure InitMainWindow; virtual;
  49.   end;
  50.  
  51.   PCopyWindow = ^CopyWindow;
  52.  
  53.   CopyWindow = object(TWindow)
  54.     SourceA, SourceB: PRadioButton;
  55.     SourceC, SourceD: PRadioButton;
  56.     TargetA, TargetB: PRadioButton;
  57.     TargetC, TargetD: PRadioButton;
  58.     MyLogPalette:PLogPalette;
  59.     BackGround:HBitmap;
  60.     EntryField1 : PEdit;
  61.     EntryField2 : PEdit;
  62.     StartButton : PButton;
  63.     Check1: PCheckBox;
  64.     Text:PStatic;
  65.     BlueBrush:HBrush;
  66.     SourceGroup: PGroupBox;
  67.     TargetGroup: PGroupBox;
  68.     constructor Init(AParent: PWindowsObject; ATitle: PChar);
  69.     procedure GetWindowClass(var AWndClass:TWndClass);Virtual;
  70.     procedure PushStartButton(var Msg: TMessage);
  71.       virtual id_First + id_Push1;
  72.     procedure HandleSourceGroup(var Msg: TMessage);
  73.       virtual id_First + id_SourceGroup;
  74.     Procedure HandleTargetGroup(var Msg: TMessage);
  75.       virtual id_First + id_TargetGroup;
  76.     Procedure WMControlColor(var Msg:TMessage);
  77.       virtual wm_First + wm_CtlColor;
  78.   end;
  79.  
  80. { -------- CopyWindow methods------------------ }
  81. constructor CopyWindow.Init(AParent: PWindowsObject; ATitle: PChar);
  82. var
  83.   AButt: PButton;
  84. begin
  85.   TWindow.Init(AParent, ATitle);
  86.   Attr.X:=105;
  87.   Attr.Y:=90;
  88.   Attr.W:=420;
  89.   Attr.H:=280;
  90.   Answer:=False;
  91.   BlueBrush := CreateSolidBrush(rgb_Blue);
  92.  
  93.   StartButton := New(PButton, Init(@Self, id_Push1, 'Start Copy',
  94.     250, 162, 100, 24, False));
  95.  
  96.   SourceGroup := New(PGroupBox, Init(@Self, id_SourceGroup, 'Source Drive',
  97.     50, 30, 103, 80));
  98.   SourceA := New(PRadioButton, Init(@Self, id_Rad1, 'A',
  99.     65, 50, 38, 24, SourceGroup));
  100.   SourceB := New(PRadioButton, Init(@Self, id_Rad2, 'B',
  101.     65, 80, 38, 24, SourceGroup));
  102.   SourceC := New(PRadioButton, Init(@Self, id_Rad3, 'C',
  103.     110, 50, 38, 24, SourceGroup));
  104.   SourceD := New(PRadioButton, Init(@Self, id_Rad4, 'D',
  105.     110, 80, 38, 24, SourceGroup));
  106.  
  107.   Text := New(PStatic, Init(@Self, Text1, '------>',185,67,50,30,0));
  108.  
  109.   TargetGroup := New(PGroupBox, Init(@Self, id_TargetGroup, 'Target Drive',
  110.     250, 30, 103, 80));
  111.   TargetA := New(PRadioButton, Init(@Self, id_Rad5, 'A',
  112.     265, 50, 38, 24, TargetGroup));
  113.   TargetB := New(PRadioButton, Init(@Self, id_Rad6, 'B',
  114.     265, 80, 38, 24, TargetGroup));
  115.   TargetC := New(PRadioButton, Init(@Self, id_Rad7, 'C',
  116.     310, 50, 38, 24, TargetGroup));
  117.   TargetD := New(PRadioButton, Init(@Self, id_Rad8, 'D',
  118.     310, 80, 38, 24, TargetGroup));
  119.  
  120.   Text := New(PStatic, Init(@Self, Text1, 'Source File Name',50,122,150,20,0));
  121.   EntryField1 := New(PEdit, Init(@Self, id_Entry1, '',50,140,180,24,0,False));
  122.   Text := New(PStatic, Init(@Self, Text2, 'Target File Name',50,172,150,20,0));
  123.   EntryField2 := New(PEdit, Init(@Self, id_Entry2, '',50,190,180,24,0,False));
  124.  
  125.   MessageBox(HWindow,'Written By Adam A. Allard','FileCopy - ver 1.2',MB_OK);
  126. End; (* Init Window *)
  127.  
  128.  
  129. procedure CopyWindow.WMControlColor(var Msg: TMessage);
  130. begin
  131.   case Msg.LParamHi of
  132.  
  133.     ctlColor_Static:
  134.       begin
  135.         SetTextColor(Msg.WParam, rgb_Red);
  136.         SetBkMode(Msg.WParam, TransParent);
  137.         Msg.Result := GetStockObject(White_Brush);
  138.       end;
  139.  
  140.     ctlcolor_Dlg:
  141.       begin
  142.         SetBkMode(Msg.WParam, Transparent);
  143.         Msg.Result := BlueBrush;
  144.       end;
  145.   else
  146.     DefWndProc(Msg);
  147.   end; (* Case *)
  148. end;
  149.  
  150. Procedure CopyWindow.GetWindowClass(var AWndClass:TWndClass);
  151. Begin
  152.   TWindow.GetWindowClass(AWndClass);
  153.   AWndClass.hIcon:=LoadIcon(HInstance, AppName);
  154. End;
  155.  
  156. Procedure CopyWindow.HandleSourceGroup(var Msg: TMessage);
  157. Begin
  158.   If (SourceA^.GetCheck <> 0) OR (SourceB^.GetCheck <> 0)
  159.         OR (SourceC^.GetCheck <> 0) OR (SourceD^.GetCheck <> 0) Then
  160.   Begin
  161.     SourceNumA:=SourceA^.GetCheck;
  162.     SourceNumB:=SourceB^.GetCheck;
  163.     SourceNumC:=SourceC^.GetCheck;
  164.     SourceNumD:=SourceD^.GetCheck;
  165.     If SourceNumA = 1 then Source := 'A';
  166.     If SourceNumB = 1 then Source := 'B';
  167.     If SourceNumC = 1 then Source := 'C';
  168.     If SourceNumD = 1 then Source := 'D';
  169.   End; (* If *)
  170. End; (* Procedure CopyWindow.HandleSourceGroup *)
  171.  
  172.  
  173. Procedure CopyWindow.HandleTargetGroup(var Msg: TMessage);
  174. Begin
  175.   If (TargetA^.GetCheck <> 0) OR (TargetB^.GetCheck <> 0)
  176.         OR (TargetC^.GetCheck <> 0) OR (TargetD^.GetCheck <> 0) Then
  177.   Begin
  178.     TargetNumA:=TargetA^.GetCheck;
  179.     TargetNumB:=TargetB^.GetCheck;
  180.     TargetNumC:=TargetC^.GetCheck;
  181.     TargetNumD:=TargetD^.GetCheck;
  182.     If TargetNumA = 1 then Target := 'A';
  183.     If TargetNumB = 1 then Target := 'B';
  184.     If TargetNumC = 1 then Target := 'C';
  185.     If TargetNumD = 1 then Target := 'D';
  186.   End; (* If *)
  187. End; (* Procedure CopyWindow.HandleTargetGroup *)
  188.  
  189.  
  190. Procedure CopyWindow.PushStartButton(var Msg: TMessage);
  191. Var
  192.   StartPos, EndPos:Integer;
  193.   StartPos2,EndPos2:Integer;
  194.   SourceFileName:Array[0..35] of Char;
  195.   TargetFileName:Array[0..35] of Char;
  196.   SourceFile,TargetFile:File;
  197.   NumRead,NumWritten:Word;
  198.   Buf:Array[1..2048] of Char;
  199.   Reply,Reply2:Integer;
  200.   CheckIt:Boolean;
  201.   CheckA,CheckB,CheckC,CheckD:Integer;
  202.   CheckAA,CheckBB,CheckCC,CheckDD:Integer;
  203. Begin
  204.   EntryField1^.GetSelection(StartPos,EndPos);
  205.   EntryField1^.GetText(SourceFileName, 35);
  206.   Checkit:=EntryField1^.IsModified;
  207.   If Checkit=False then
  208.     Begin
  209.       MessageBox(HWindow,'You Must Enter A Source File Name','Copy Status',MB_OK+MB_IconExclamation);
  210.       Exit;
  211.     End;
  212.   CheckA:=SourceA^.GetCheck;
  213.   CheckB:=SourceB^.GetCheck;
  214.   CheckC:=SourceC^.GetCheck;
  215.   CheckD:=SourceD^.GetCheck;
  216.   If (CheckA=0) AND (CheckB=0) AND (CheckC=0) AND (CheckD=0) then
  217.     Begin
  218.       MessageBox(HWindow,'You Must Enter A Source Drive','Copy Status',MB_OK+MB_IconExclamation);
  219.       Exit;
  220.     End;
  221.   CheckAA:=TargetA^.GetCheck;
  222.   CheckBB:=TargetB^.GetCheck;
  223.   CheckCC:=TargetC^.GetCheck;
  224.   CheckDD:=TargetD^.GetCheck;
  225.   If (CheckAA=0) AND (CheckBB=0) AND (CheckCC=0) AND (CheckDD=0) then
  226.     Begin
  227.       MessageBox(Hwindow,'You Must Enter A Target Drive','Copy Status',MB_OK+MB_IconExclamation);
  228.       Exit;
  229.     End;
  230.   If Answer=False then
  231.     Begin
  232.       EntryField2^.SetText(SourceFileName);
  233.       EntryField2^.GetText(TargetFileName,35);
  234.       Answer:=True;
  235.       Reply := MessageBox(HWindow, 'Change Target File Name?','Copy Status', MB_YesNo+MB_IconQuestion);
  236.         If Reply = id_Yes then Exit;
  237.     End;
  238.  
  239.   EntryField2^.GetText(TargetFileName,35);
  240.   Assign(SourceFile,Source+':\'+SourceFileName);
  241.   Reset(SourceFile,1);
  242.   If IOResult <> 0 then
  243.     Begin
  244.       MessageBox(HWindow,'File Not Found','Copy Status',MB_OK+MB_IconStop);
  245.         Answer:=False;
  246.         EntryField1^.SetText('');
  247.         EntryField2^.SetText('');
  248.         SourceA^.SetCheck(0);
  249.         SourceB^.SetCheck(0);
  250.         SourceC^.SetCheck(0);
  251.         SourceD^.SetCheck(0);
  252.         TargetA^.SetCheck(0);
  253.         TargetB^.SetCheck(0);
  254.         TargetC^.SetCheck(0);
  255.         TargetD^.SetCheck(0);
  256.       Exit;
  257.     End;
  258.   Assign(TargetFile,Target+':\'+TargetFileName);
  259.   ReWrite(TargetFile,1);
  260.     Repeat
  261.       BlockRead(SourceFile,Buf,SizeOf(Buf), NumRead);
  262.       BlockWrite(TargetFile,Buf,NumRead,NumWritten);
  263.     Until (NumRead = 0) or (NumWritten <> NumRead);
  264.   Close(SourceFile);
  265.   Cl